﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchoolManagementSystem.Controls;
using CoreData;

namespace SchoolManagementSystem.Details
{
    public partial class AttributeUC : DetailUC
    {
        public AttributeUC()
        {
            InitializeComponent();
            this.ObjectName = "Thuộc tính hàng hóa";
            this.Code = "Attribute";
            this.Type = new CoreData.Attribute();
        }
        protected override long DetailDisplay()
        {
            CoreData.Attribute data = new CoreData.Attribute();
            if (ID > 0)
            {
                data = (CoreData.Attribute)RegisterService.RegisterServices.AttributeService.GetByID(ID);

            }
            txtname.Text = data.Name;
            txtnote.Text = data.Description;
            txtcode.Text = data.Code;
            ckactive.Checked = data.Active;

            return ID;

        }

        protected override long Save()
        {
            CoreData.Attribute data = new CoreData.Attribute();
            if (ID > 0)
            {
                data = (CoreData.Attribute)RegisterService.RegisterServices.AttributeService.GetByID(ID);

            }
            data.Code = txtcode.Text;
            data.Name = txtname.Text;
            data.Description = txtnote.Text;
            data.Active = ckactive.Checked;

            ID = RegisterService.RegisterServices.BranchService.Save(data, ref ErrorMess);

            return ID;
        }


        public override bool Delete(long SelectedID)
        {
            //var check = RegisterService.RegisterServices.CourseService.GetbyBranchID(SelectedID);
            //if (check != null && check.Count != 0)
            //{
            //    ErrorMess = "Vui lòng xóa các khóa học liên quan trước khi xóa ngành học này";
             return false;
            //}
            //else
            //{
            //    //return RegisterService.RegisterServices.BranchService.Delete(RegisterService.RegisterServices.BranchService.GetByID(SelectedID));
            //    return RegisterService.RegisterServices.BranchService.UpdateIsDelete(RegisterService.RegisterServices.BranchService.GetByID(SelectedID));
            //}
        }


        private void AtrributeUC_Load(object sender, EventArgs e)
        {
            AddTextChanged(groupControl1.Controls);
        }
    }
}
